from selenium.webdriver.common.by import By

from base.page_base import BasePage
from config import BACK_URL


class TestopenBackend(BasePage):
    account = (By.ID, 'username')
    password = (By.ID, 'password')
    code = (By.ID, 'valicode')
    open_01 = (By.CLASS_NAME, 'login-button')
    # 成功文本元素
    success_text = (By.XPATH, '/html/body/div[1]/div[3]/ul/li[2]/a/span/div')

    def open_url_01(self):
        self.driver.get(BACK_URL)

    def input_account(self, account):
        """输入账号"""
        self.base_input(self.account, account)

    def input_password(self, password):
        """输入密码"""
        self.base_input(self.password, password)

    def input_code(self, code):
        """输入验证码"""
        self.base_input(self.code, code)

    def click_open(self):
        self.base_click(self.open_01)

    def get_succes_text(self):
        return self.fd_element(self.success_text).text

    def Admin_Login(self, account, password, code):
        self.input_account(account)
        self.input_password(password)
        self.input_code(code)
        self.click_open()
